package com.fishing.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.spring.util.CustomerContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fishing.entity.Admin;
import com.fishing.mapper.AdminMapper;
import com.fishing.service.AdminService;

@Service
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminMapper adminMapper;

	/*
     * 特殊的instance变量
     * 注：零长度的byte数组对象创建起来将比任何对象都经济――查看编译后的字节码：
     * 生成零长度的byte[]对象只需3条操作码，而Object lock = new Object()则需要7行操作码。
     */
private static byte[] lock = new byte[0];
	
	@Override
	public int deleteByPrimaryKey(Integer id)throws Exception {
		return this.adminMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Admin record)throws Exception {
		record.setState((byte) 0);
		record.setTruename(record.getLoginid());
		record.setUserType("0");
		record.setCreatetime(new Date());
		return this.adminMapper.insert(record);
	}

	@Override
	public Admin selectByPrimaryKey(Integer id)throws Exception {
		return this.adminMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Admin> selectAll(Map<String,Object> map)throws Exception {
		return this.adminMapper.selectAll(map);
	}

	@Override
	public int updateByPrimaryKey(Admin record)throws Exception {
		return this.adminMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updatePwd(Admin record) throws Exception {
		return this.adminMapper.updatePwd(record);
	}

	@Override
	public int updateState(Integer id, byte state) throws Exception {
		Admin record = new Admin();
		record.setId(id);
		record.setState(state);
		return this.adminMapper.updateState(record);
	}

	@Override
	public int selectExist(Admin record) throws Exception {
		return this.adminMapper.selectExist(record);
	}

	@Override
	public Admin selectByLoginId(String loginId) throws Exception {
		return this.adminMapper.selectByLoginId(loginId);
	}

	@Override
	public Admin selectByOpenIdAndUnionId(String openIdWx, String unionIdWx) throws Exception {
		Admin record = new Admin();
		return this.adminMapper.selectByOpenIdAndUnionId(record);
	}

	@Override
	public int insertByThird(Admin record) throws Exception {
		return this.adminMapper.insertByThird(record);
	}

	@Override
	public int updateForAudit(Admin record) throws Exception {
		return this.adminMapper.updateForAudit(record);
	}

	@Override
	public int test(String name) throws Exception {
		 synchronized(lock) {
			 System.out.println("name:"+name+","+new Date());
	     }
		return 0;
	}

}
